package com.whj.apipassenger.service.impl;

import com.whj.apipassenger.remote.ServicePassengerUserClient;
import com.whj.apipassenger.service.UserService;
import com.whj.internalcommon.dto.PassengerUser;
import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.dto.TokenResult;
import com.whj.internalcommon.request.VerificationCodeDTO;
import com.whj.internalcommon.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: wanghaijun
 * @Date: 2023/1/4 - 01 - 04 - 13:16 
 * @Description: com.whj.apipassenger.service.impl
 */

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    /**
     * 根据解析accessToken的手机号来查询用户信息
     *
     * @param accessToken
     * @return
     */
    @Override
    public ResponseResult getUserByToken(String accessToken) {

        //解析token，拿到手机号
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        String phone = tokenResult.getPhone();

        //根据手机号查询用户信息
        ResponseResult<PassengerUser> passengerUser = servicePassengerUserClient.getUserByPhone(phone);

        return ResponseResult.success(passengerUser.getData());
    }
}
